package com.lsw.jgyf.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;

import com.lsw.Base.AdapterRefresh;
import com.lsw.jgyf.R;
import com.lsw.jgyf.adapter.MoreOptionsAdapter;
import com.lsw.jgyf.model.MoreOptionsModel;
import com.lsw.jgyf.ui.base.activity.TitleBarActivity;
import com.lsw.pullableview.PullToRefreshLayout;
import com.lsw.pullableview.PullableListView;
import com.lsw.util.LogUtils;
import com.lsw.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by lsw on 2018/7/11.
 */

public class MoreOptionsActivity extends TitleBarActivity<MoreOptionsPresenter> implements MoreOptionsContract.View, AdapterRefresh, PullToRefreshLayout.OnRefreshListener {
    @BindView(R.id.pullToRefreshLayout)
    PullToRefreshLayout pullToRefreshLayout;
    @BindView(R.id.pullableListView)
    PullableListView pullableListView;
    MoreOptionsAdapter moreOptionsAdapter;
    String price, first_money, insurance_id, num, periods;

    @Override
    protected void initInjector() {
        mActivityComponent.inject(this);
    }

    @Override
    protected void initEventAndData() {
        pullToRefreshLayout.setOnRefreshListener(this);
        pullableListView.setCanPulldown(true);
        price = getIntent().getStringExtra("price");
        first_money = getIntent().getStringExtra("first_money");
        insurance_id = getIntent().getStringExtra("insurance_id");
        num = getIntent().getStringExtra("num");
        periods = getIntent().getStringExtra("periods");
        moreOptionsAdapter = new MoreOptionsAdapter(mContext);
        moreOptionsAdapter.setAdapterRefresh(this);
        pullableListView.setAdapter(moreOptionsAdapter);
        LogUtils.i("lsw", "price=" + price + ",first_money=" + first_money + ",insurance_id=" + insurance_id + ",num=" + num);
        mPresenter.getData(price, first_money, insurance_id, num, periods);
    }

    @Override
    protected int setContentLayoutView() {
        return R.layout.activity_more_options;
    }

    @Override
    public void onRefreshAdapter(int position, int taskid) {
        if (taskid == 1) {
            Intent intent = new Intent();
            intent.putExtra("data", moreOptionsAdapter.getList().get(position));
            setResult(RESULT_OK, intent);
            finish();
        }
    }

    @Override
    public void setData(List<MoreOptionsModel> list) {
        if (list.size() == 0) {
            ToastUtil.showToast(mContext, "没有更多方案！");
        } else
            moreOptionsAdapter.setData(list);
    }

    @Override
    public void RefreshSucceed() {
        pullToRefreshLayout.Resultfinish(PullToRefreshLayout.SUCCEED);
    }

    @Override
    public void RefreshFail() {
        pullToRefreshLayout.Resultfinish(PullToRefreshLayout.FAIL);
    }

    @Override
    protected void setActionBarDetail() {

    }

    @Override
    public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
        mPresenter.getData(price, first_money, insurance_id, num, periods);
    }

    @Override
    public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {

    }

    @Override
    public void openlogin() {
        OpenLogin();
    }
}
